﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Domain.Core
{
    /// <summary>
    /// 模型基类
    /// </summary>
    public abstract class EntityBase
    {
        /// <summary>
        /// 实体是否验证通过
        /// </summary>
        /// <returns></returns>
        public virtual bool IsValidation()
        {
            return GetValidation() == null
                || GetValidation().Count() == 0;
        }
        /// <summary>
        /// 失败消息
        /// </summary>
        public string ValidationMessage
        {

            get
            {
                StringBuilder str = new StringBuilder();
                if (GetValidation() != null && GetValidation().Count() > 0)
                {
                    GetValidation().ToList().ForEach(i =>
                    {
                        str.Append(i);
                    });
                }
                return str.ToString();
            }
        }
        /// <summary>
        /// 迭代返回验证结果
        /// </summary>
        /// <returns></returns>
        protected virtual IEnumerable<string> GetValidation()
        {
            throw new NotImplementedException();
        }
    }
}
